//
//  tagCell.m
//  婚礼纪  首页
//
//  Created by 太阳 on 15/5/16.
//  Copyright (c) 2015年 三人. All rights reserved.
//

#import "tagCell.h"
#import "RecommendModel.h"
#import "UIImageView+WebCache.h"
#import "ConnectionModel.h"
@implementation tagCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self= [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellAccessoryNone;
        [self requestNet];
        
    }
    return self;
}
- (void)requestNet
{
    [ConnectionModel connectDoneWithStr:@"http://hunliji.com/v1/api/app/marks/recommend" block:^(NSData *data) {
        self.bigarray = [NSMutableArray array];
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSArray *array = [dic objectForKey:@"marks"];
        for (NSDictionary *seconddic in array) {
            RecommendModel *model = [[RecommendModel alloc]init];
            [model setValuesForKeysWithDictionary:seconddic];
            [self.bigarray addObject:model];
        }
        [self createview];
    }];
}

- (void)createview
{
    int i = 0;
    CGFloat a = [UIScreen mainScreen].bounds.size.width / 3.505;
    for (RecommendModel *model in self.bigarray) {
        UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(i % 3 * (a+10)  + 15, i / 3 * (a + 10) + 10, a, a)];
//        [image setBackgroundColor:[UIColor yellowColor]];
        [image sd_setImageWithURL:[NSURL URLWithString:model.image_path] placeholderImage:nil options:SDWebImageRetryFailed];
//        image.layer.allowsEdgeAntialiasing = NO;
        image.layer.cornerRadius = 10;
//        image.layer.allowsGroupOpacity = YES;
        NSString *str = [NSString stringWithFormat:@"%@",model.name];
        NSDictionary *dicc = @{NSFontAttributeName:[UIFont systemFontOfSize:15]};
        CGRect rect = [str boundingRectWithSize:CGSizeMake(0, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dicc context:nil];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(a / 1.5, 10, 25, rect.size.width + 15)];
        label.textAlignment = NSTextAlignmentCenter;
        label.numberOfLines = 0;
        label.font = [UIFont systemFontOfSize:15];
        label.layer.cornerRadius = 4;
        label.text = str;
         label.textColor = [UIColor colorWithWhite:0.4 alpha:1];
        [label setBackgroundColor:[UIColor whiteColor]];
        [image addSubview:label];
        
        [self addSubview:image];
        i++;
    }
}
@end
